<!--#Include File="../conn.asp" -->
<!--#Include File="comm/inc.asp" -->
<%
'====================================================================
'= Team Elite - Elite Article System
'= Copyright (c) 2005 - 2006 Eason Chan All Rights Reserved.
'=-------------------------------------------------------------------
'= 版权协议：
'=	GPL (The GNU GENERAL PUBLIC LICENSE Version 2, June 1991)
'=-------------------------------------------------------------------
'= 文件名称：/Manager/Admin_LoadSkin.asp
'= 摘    要：后台-风格导入导出文件
'=-------------------------------------------------------------------
'= 最后更新：eason007
'= 最后日期：2005-10-11
'====================================================================

Call EA_Manager.Chk_IsMaster

If Not EA_Manager.Chk_Power(Admin_Power,"45") Then 
	ErrMsg=str_Comm_NotAccess
	Call EA_Manager.Error(1)
End If

Dim Atcion,TempConn
Atcion=Request.QueryString ("action")

Dim mdbName

Select Case Atcion
Case "load"
	Call Load()
Case "saverename"
	Call SaveReName()
	Call Main()
Case "operation"
	Select Case Request.Form ("submit")
	Case str_Skin_Output
		OutputTemplate()
	Case str_Skin_Input
		InputTemplate()
	End Select
Case Else
	Call Main()
End Select
Call EA_Pub.Close_Obj
Set EA_Pub=Nothing

Sub Main()
	Dim Operation
	Dim Temp,ListBlock

	If Atcion="loadthis" Then
		Operation=str_Skin_Input
	Else
		Operation=str_Skin_Output
	End If
	mdbName=Trim(Request.Form ("mdbname"))
	If mdbName = "" Then mdbName = "databackup/nb_template.mdb"

	PageContent=Template.LoadTemplate("admin_loadskin_main.htm")

	Template.SetVariable "Language_Comm_SelectAll",str_Comm_SelectAll,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Skin_Help",str_Skin_Help,PageContent

	Template.SetVariable "Language_Template_TempName",str_Template_TempName,PageContent
	Template.SetVariable "Language_Skin_Choice",str_Skin_Choice,PageContent
	Template.SetVariable "Language_Skin_Database",str_Skin_Database,PageContent
	Template.SetVariable "Language_Skin_InputTemplate",str_Skin_InputTemplate,PageContent
	Template.SetVariable "Language_Skin_OutputTemplate",str_Skin_OutputTemplate,PageContent
	Template.SetVariable "mdbName",mdbName,PageContent
	Template.SetVariable "Operation",Operation,PageContent

	ListBlock=Template.GetBlock("list",PageContent)

	SQL="Select [Id],Temp_Name From [NB_Template] Order By Id "

	If Atcion="loadthis" Then
		ConnectionSkinDataBase(mdbname)
		Set Rs=TempConn.Execute(SQL)
	Else
		Set Rs=Conn.Execute(SQL)
	End If

	Do While Not Rs.eof
		Temp=ListBlock

		Template.SetVariable "TemplateName",Rs("Temp_Name"),Temp
		Template.SetVariable "TemplateID",Rs("id"),Temp

		Template.SetBlock "list",Temp,PageContent
		Rs.movenext
	Loop
	Template.CloseBlock "list",PageContent

	Rs.Close:Set Rs=Nothing
	If Atcion="loadthis" Then TempConn.Close:Set TempConn=Nothing

	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub Load()
	PageContent=Template.LoadTemplate("admin_loadskin_input.htm")

	Template.SetVariable "Language_Comm_Next",str_Comm_Next,PageContent

	Template.SetVariable "Language_OperationNotice",str_OperationNotice,PageContent
	Template.SetVariable "Language_Skin_Help",str_Skin_Help,PageContent

	Template.SetVariable "Language_Skin_InputTemplate",str_Skin_InputTemplate,PageContent
	Template.SetVariable "Language_Skin_OutputTemplate",str_Skin_OutputTemplate,PageContent
	Template.SetVariable "Language_Skin_Database",str_Skin_Database,PageContent
	

	Template.BaseReplace PageContent
	Template.OutStr PageContent
End Sub

Sub OutputTemplate()
	On Error Resume Next

	Dim TempId,TmpArray
	Dim TmpRs
	Dim i
	
	TempId=EA_Pub.SafeRequest(2,"tempid",1,"",0)
	
	ConnectionSkinDataBase(Request.Form ("dbname"))

	If TempId<>"" Then 
		Set TmpRs=Server.CreateObject("adodb.recordSet")
		SQL="Select * From [NB_Template]"
		TmpRs.Open SQL,TempConn,2,3
		
		SQL="Select * From [NB_Template] Where Id In ("&TempId&")"
		Set Rs=Conn.Execute(SQL)
		
		Do While Not rs.eof
			TmpRs.AddNew
			
			For i=1 To TmpRs.Fields.Count-1
				TmpRs(TmpRs(i).Name)=Rs(TmpRs(i).Name)
			Next
			
			TmpRs.Update 
			Rs.MoveNext
		Loop
		
		TempRs.Close:Set TempRs=Nothing
		TempConn.Close:Set TempConn=Nothing
		
		ErrMsg=str_Skin_CopyComplete
		Call EA_Manager.Error(0)
	End If
	
	Call EA_Pub.Close_Obj
	Set EA_Pub=Nothing
	
	Response.Redirect Request.ServerVariables("HTTP_REFERER")
End Sub

Sub InputTemplate()
	On Error Resume Next
	
	Dim TempId,TmpArray
	Dim TmpRs
	Dim i
	
	TempId=EA_Pub.SafeRequest(2,"tempid",1,"",0)
	
	ConnectionSkinDataBase(Request.Form ("dbname"))

	If TempId<>"" Then 
		Set Rs=Server.CreateObject("adodb.recordSet")
		SQL="Select * from [NB_Template]"
		Rs.Open SQL,Conn,2,3
		
		SQL="Select * from [NB_Template] Where Id In ("&TempId&")"
		Set TmpRs=TempConn.Execute(SQL)
		'Response.Write sql
		
		Do While Not TmpRs.eof
			Rs.AddNew
			
			For i=1 To Rs.Fields.Count-1
				'Response.Write i&Rs.Fields.Count&Rs(i).Name&"<br>"
				'Response.Flush 
				Rs(Rs(i).Name)=TmpRs(Rs(i).Name)
			Next
			
			Rs.Update 
			TmpRs.MoveNext
		Loop
		
		TempRs.Close:Set TempRs=Nothing
		TempConn.Close:Set TempConn=Nothing
		
		ErrMsg=str_Skin_CopyComplete
		Call EA_Manager.Error(0)
	End If
	
	Call Main()
End Sub

Sub ConnectionSkinDataBase(mdbname)
	On Error Resume Next 
	Err.Clear 
	
	Set TempConn = Server.CreateObject("ADODB.Connection")
	TempConn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(mdbname)
	
	If Err  Then 
		ErrMsg="在打开数据库[ <font color=red>"&mdbname&"</font> ]时发生如下错误："
		ErrMsg=ErrMsg&"<li>"&Err.Description 
		Call EA_Manager.Error(1)
	End If
End Sub
%>